import { defineStore } from "pinia";
import { ref, watchEffect } from "vue";
import type {
  AviationData,
  DownloadData,
  HomeData,
  NavPanelData,
  OnePageData,
  ProfileData,
  SupportData,
} from "../../types/cache";

export const useCacheStore = defineStore("cacheStore", () => {
  const touchActionDiabled = ref(false);

  const bannerData = ref<any[]>([]);
  const onePageData = ref<OnePageData>({});
  const navPanelData = ref<NavPanelData>({
    aviation: {},
    job: {},
    rent: {},
    support: {},
  });

  const homeData = ref<HomeData>({});
  const aviationData = ref<AviationData>({
    swiper: [],
    tables: [],
  });
  const supportData = ref<SupportData>({
    baseRepair: {},
    componentModify: {},
    airLine: {},
  });
  const lmData = ref<any>();
  const downloadData = ref<DownloadData>({
    fileList: [],
  });

  // profile
  const profileData = ref<ProfileData>({
    exam: {},
  });
  const clearAll = () => {
    touchActionDiabled.value = false;
    onePageData.value = {};
    bannerData.value = [];
    navPanelData.value.aviation = {};
    navPanelData.value.job = {};
    navPanelData.value.rent = {};
    navPanelData.value.support = {};
    homeData.value = {};
    aviationData.value.swiper = [];
    aviationData.value.tables = [];
    supportData.value.baseRepair = {};
    supportData.value.componentModify = {};
    supportData.value.airLine = {};
    lmData.value = null;
    downloadData.value.fileList = [];
    profileData.value.exam.courseList = undefined;
  };

  return {
    touchActionDiabled,
    bannerData,
    homeData,
    onePageData,
    supportData,
    lmData,
    downloadData,
    navPanelData,
    aviationData,
    profileData,
    clearAll,
  };
});
